<template>
    <el-dialog :modelValue="popShow" title="编辑"  width="30%" center :show-close="false" >
        <el-form :model="editData" ref="ruleFormRef">
            <el-form-item label="课程名称" prop="title" required>
                <el-input v-model="editData.title"/>
            </el-form-item>
            <el-form-item label="课程学分" prop="point" required>
                <el-input v-model="editData.point"/>
            </el-form-item>
            <el-form-item>
                <el-button @click="confirmClick('cancel')">取消</el-button>
                <el-button type="primary" @click="submitForm(ruleFormRef)" >确定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script setup>
import { defineProps, reactive,ref } from 'vue';
const {popShow,message,confirmClick} = defineProps(['popShow','message','confirmClick']);
const  editData = reactive({
    title: message.title,
    point: message.point,
    id:message.id
})
console.log(popShow)
const ruleFormRef = ref(null)
// 表单提交验证（确认）
const submitForm = async(formEl) => {
    if (!formEl) return
    // 拿到数据
    await formEl.validate((valid, fields) => {
        // valid  true是否通过验证（标题和学分不为空）,fields 未通过验证的字段
        if (valid) {
            confirmClick({
                title:editData.title,
                point:editData.point,
                id:editData.id
            })
        } else {
            console.log('error submit!')
            return false
        }
    })
}

</script>

<style>
</style>